package org.angelica.aliyun.config;
import org.angelica.aliyun.manager.OpenSearchManager;
import org.angelica.aliyun.manager.StsManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 应用启动时初始化配置对象
 * @author aizhimin
 */
@Configuration
public class AliyunConfig {
    /**
     * 初始化阿里云sts凭证服务
     */
    @Value("${aliyun.sts.access-key-id}")
    private String aliyunAccessKeyId;
    @Value("${aliyun.sts.access-key-secret}")
    private String aliyunAccessKeySecret;
    @Value("${aliyun.sts.endpoint}")
    private String stsEndpoint;
    @Bean
    public StsManager stsManager(){
        return new StsManager(stsEndpoint,aliyunAccessKeyId,aliyunAccessKeySecret);
    }

    /**
     * 初始化阿里云opensearch服务：由于开放搜索暂时不支持sts授权，所以使用RAM子账号模式
     */
    @Value("${aliyun.opensearch.access-key-id}")
    private String opensearchAccessKeyId;
    @Value("${aliyun.opensearch.access-key-secret}")
    private String opensearchAccessKeySecret;
    @Value("${aliyun.opensearch.host}")
    private String opensearchHost;
    @Value("${aliyun.opensearch.appname}")
    private String opensearchAppname;
    @Value("${aliyun.opensearch.suggestion-name}")
    private String opensearchSuggestName;
    @Bean
    public OpenSearchManager openSearchManager(){
        return new OpenSearchManager(opensearchAccessKeyId,opensearchAccessKeySecret,opensearchHost,opensearchAppname,opensearchSuggestName);
    }
}
